#include <stdio.h>
#include "other.h"
#include <string.h>
int giantxs = 5;


void showPrice(double rate,int nights){
     int pooth =10;
     printf("The total price is $%0.2f &pooth=%p\n",rate*nights,&pooth);
}

void interchange2(int * u,int * v){
     int temp;
     temp = *u;
     *u = *v;
     *v = temp;
}

void interchage1(int u,int v){
     int temp;
     temp = u;
     u = v;
     v = temp;
}

int sum(const int arr[],int n){
     int i;
     int total =0;
     for (i = 0; i < n; i++)
     {
        total += arr[i]; //error arr[i]++

     }
     return total;
}

void test(){
     double rates[5] = {88.99,100.00,120.00,140.00,160.00};
     const double * pd = rates;

     printf("pd[2]= %f\n",pd[2]);

     // pd[2] = 100.00;// 不允许

     const double locked[4]={100.00,120.00,140.00,160.00};
     double locked2[4]={100.01,120.02,140.03,160.04};

     const double * pc = rates;


     // 把const数据或非const数据的地址初始化为指向const的指针或为其赋值是合法的
     pc = locked; // 允许
     pc = &rates[2]; // 允许
     pc = locked2;


     // 只能把非const数据的地址赋给普通指针
     double * pnc = rates;
     // pnc = locked; // 不允许  这个规则合理。否则，通过指针就能改变const数组中的数据
     //pnc = &rates[2]; // 允许
     //pnc = locked2; // 允许

     printf("pnc[2]= %f\n",pnc[2]);

     double * const pr = rates; // 把pr初始化为指向rates的const指针,可以用这种指针修改它所指向的值，但是它只能指向初始化时设置的地址
     // pr = &rates[2]; // 不允许  -- const指针不能改变指向的地址

     *pr = 92.99; // 允许 -- 更改rates[0]的值

     const double * const pcr = rates; // 把pcr初始化为指向const的const指针，该指针既不能更改它所指向的地址，也不能修改指向地址上的值。
     // pcr = &rates[2]; // 不允许
     // *pcr = 92.99; // 不允许

     int zippo[4][2] = {{2,4},{6,8},{1,3},{5,7}};//zippo 、zippo[0]、&zippo[0][0] 值相同



     //指向数组的指针
     int (* pz)[2];//pz 指向一个内含两个int 类型的数组的指针 方括号的优先级高于*。
     pz = zippo;

     int * pax[2];//paz 是一个指向两个指针元素的数组，每个元素都指向int的指针。（方括号的优先级高于*）


     printf("zippo=%p,zippo +1 =%p\n",zippo,zippo+1);
     printf("pz=%p,pz +1 =%p\n",pz,pz+1);


     

}

int vla_sum2(int rows,int cols,int ar[rows][cols]){
     int i,j;
     int total =0;
     for ( i = 0; i < rows; i++)
     {
        for ( j = 0; j < cols; j++)
        {
            total += ar[i][j];
        }
     }
     return total;
}

int vla_sum(int rows,int cols,int ar[rows][cols]){
     int i,j;
     int total =0;
     for ( i = 0; i < rows; i++)
     {
        for ( j = 0; j < cols; j++)
        {
            total += ar[i][j];
        }
     }
     return total;
}

int findWords(){
     const char* list[6] ={"asrtonomy","asrtfgfg","asrtrtty","asrtrtty","asrtrtdty","aqqtdrtty"};
     int count =0;
     int i;

     for ( i = 0; i < 6; i++)
     {
         if (strncmp(list[i],"asrt",4) == 0)
         {
          printf("Found:%s\n",list[i]);
          count++;

         }
         
     }
     printf("The list contained %d words beginning with asrt.\n",count);

      // 链接、作用域
    //  printf("外部链接 giantxs=%s\n",giantxs);
     return count;

}